﻿var weixin = function () { };

weixin.config = {
    //微信服务号appId
    appId: "wxb1f3698b4c90dccd",
    tokenBaseUrl: "../../api/accesstoken/"
    }

weixin.getBaseAuthUrl = function (redirectUri) {
    var _baseAuthUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + weixin.config.appId + "&redirect_uri=" + redirectUri + "&response_type=code&scope=snsapi_base&state=1#wechat_redirect";
    return _baseAuthUrl;
}

weixin.getQueryString = function (name) {
    var _reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var _r = window.location.search.substr(1).match(_reg);
    if (_r != null) return unescape(_r[2]);
    return null;
}

weixin.getOpenId = function (success, failure) {
    var _code = weixin.getQueryString("code");
    var _tokenUrl = "../api/accesstoken/?code=" + _code;

    axios.get(_tokenUrl).then(function (response) {
        console.log(response)

        var _openId;
        _openId = response.data;

        success(_openId);

    }).catch(function (error) {
    
        failure(error);
    });
}